<template>
  <div class="icon-list" >
    <swiper>
      <swiper-slide v-for="(page,index) in pages" :key="index">
         <div class="icon" v-for="icon in page" :key="icon.id">
          <icon-item :itemImg="icon"></icon-item>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script scoped>
import IconItem from './IconItem'

export default {
  name: 'Icons',
  props: {
    iconsList: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {}
  },
  components: {
    IconItem
  },
  computed: {
    pages () {
      const pages = []
      this.iconsList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang='less' scoped>
.icon-list /deep/ .swiper-container{
  height: 0;
  padding-bottom: 50%;
}
.icon-list{
  width: 100%;
  margin-top: 0.2rem;
  .icon{
     position: relative;
      overflow: hidden;
      float: left;
      width: 25%;
      height: 0;
      padding-bottom: 25%;
  }
}
</style>
